layui.config({
	base : "../../js/"
}).use(['flow','form','layer','upload','util'],function(){
    var flow = layui.flow,
        form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    var util = layui.util;
    
    //回到顶部
    util.fixbar({
    	top: true
    	,click: function(type){
			// if(type === 'top'){
			// 	layer.msg('点击了top');
			// }
    	}
    });

    //流加载图片
    var imgNums = 15;  //单页显示图片数量
    flow.load({
        elem: '#Images', //流加载容器
        done: function(page, next){ //加载下一页
            $.get("/miaosha/list",function(res){
                //模拟插入
                var imgList = [],data = res.data;
                var maxPage = imgNums*page < data.length ? imgNums*page : data.length;
                setTimeout(function(){
                    for(var i=imgNums*(page-1); i<maxPage; i++){
                        // 缩略图url
                        var thumb = data[i].goodsImg;
                        imgList.push('<li class="goods"><img layer-src="'+ data[i].goodsImg +'" src="'+ thumb +'" alt="'+data[i].goodsName+'" id="'+data[i].id+'"/><div class="operate"><div class="check"><input type="checkbox" name="belle" lay-filter="choose" lay-skin="primary" title="'+data[i].goodsName+'"></div></div></li>');
                    }
                    next(imgList.join(''), page < (data.length/imgNums));
                    // 渲染
                    form.render();
                    // 调整宽高
                    $("#Images li img").height($("#Images li img").width());

                    $("img").click(function (data) {
                        location.href = "/page/goods_detail.htm?goodsId="+data.currentTarget.id;
                    });
                }, 100);
            });
        }
    });

    //设置图片的高度
    $(window).resize(function(){
        $("#Images li img").height($("#Images li img").width());
    });

});